using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace GameShow.Forms
{
    public partial class frmEntertaiment : frmBase
    {
        public int seconds = 7;
        public int minutes = 0;
        public bool paused = false;  //Trang thai time: Pauser, Working
        public bool isTimeout = false;  //Da het gio chua

        public frmEntertaiment()
        {
            InitializeComponent();

            lblTime.Text = "07:00";
        }

        private void timer_Tick(object sender, EventArgs e)
        {
            // Truong hop het gio
            if ((minutes == 0) && (seconds == 0))
            {
                //Truong hop het gio, dong h se chay tien
                isTimeout = true;
                minutes = 0;
                seconds = 1;

                lblTime.ForeColor = Color.Red;
            }

            //Truong hop chua het gio, dong ho dem nguoc
            else if (isTimeout == false)
            {
                if (seconds < 1)
                {
                    seconds = 59;
                    if (minutes == 0)
                    {
                        minutes = 59;
                    }
                    else
                    {
                        minutes -= 1;
                    }
                }
                else
                    seconds -= 1;
            }

            //Truong hop het gio, dong ho chay tien
            else
            {
                if (seconds == 59)
                {
                    seconds = 00;
                    minutes++;
                }
                else
                    seconds++;
            }

            string min = minutes < 10 ? "0" + minutes.ToString() : minutes.ToString(); 
            string sec = seconds < 10 ? "0" + seconds.ToString() : seconds.ToString();

            lblTime.Text = min + ":" + sec;

        }

        protected override void Reset()
        {                       

        }

        protected override void Start(int minutes, int second)
        {
            this.minutes = minutes;
            this.seconds = second;

            timer.Enabled = true;

            base.Start(minutes, second);
        }

        protected override void Pause()
        {
            timer.Enabled = false;
            paused = true;

            base.Pause();
        }

        protected override void Stop()
        {
            // Stop the timer.
            paused = false;
            timer.Enabled = false;

            base.Stop();
        }

        protected override void DisplayWaitScreen()
        {
            base.DisplayWaitScreen();
            this.Visible = false;
            AppInstance.ShowPlayer00(5);
        }

        public override void StartForm()
        {
            lblTime.Text = "07:00";
            lblTime.ForeColor = Color.Blue;
            paused = false;
            timer.Enabled = false;
            isTimeout = false;
            
            base.StartForm();
            this.Visible = true;
            this.Show();
        }
    }
}